'''
Created on 24 Oct 2012

@author: quirino.brizi
'''
from org.codesketch.loadit.common import Writer
from org.codesketch.loadit.configuration.parser import XmlConfigurationParser
from org.codesketch.loadit.utils import instance
import sys, traceback

class Starter(object):
    
    def start(self):
        try :
            # load and parse configuration file
            configuration = XmlConfigurationParser.parse('configuration.xml');
            # starting response-recrd writer
            writer = Writer(configuration)
            writer.start();
            # load and start requested runner
            script = configuration.getScript()
            module, clazz = script.getClass().rsplit('.',1)
            runner = instance(module, clazz)
            runner.configure(configuration, writer)
            runner.execute()
            # stop writer before quit the test
            writer.stop()
        except :
            traceback.print_exc()
            return 1
        finally:
            return 0
        

if __name__ == '__main__' : sys.exit(Starter().start())